Estoy importando Vue.js por CDN y el método "eliminar" no funcionó:
<sidebar :cart="cart" :remove="removeItem" /> <script src="https://unpkg.com/vue@next"></script> <script> let app = Vue.createApp({ data() { return { cart: {} } }, methods: { addToCart(name,index) { if (!this.cart[name]) this.cart[name]=0 this.cart[name] += this.inventory[index].quantity this.inventory[index].quantity=0 }, removeItem(name){ delete this.cart[name] } }) app.component('sidebar',{ props:['cart','remove'], template:` <aside class="cart-container"> <tbody> <tr v-for="(quantity,key,i) in cart" :key="i"> <td><i class="icofont-carrot icofont-3x"></i></td> <td>{{key}}</td> <td>\${{getPrice(key)}}</td> <td class="center">{{quantity}}</td> <td>\${{ (quantity*getPrice(key)).toFixed(2) }}</td> <td class="center"> <button @click="remove(key)" class="btn btn-light cart-remove"> × </button> </td> </tr> </tbody>el google chrome dio el error de que:
Me dijeron que esta solución alternativa solo aparece cuando se usa CDN, no npm. Pero todavía me pregunto por qué "eliminar" aquí no se considera una función. Gracias por delante.